package com.dyzx.hbb.common.base;

import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.util.List;

@EqualsAndHashCode(callSuper = true)
@Data
public class PageResult<T> extends Result<T> {

    private long total;


    private long current;

    private long size;
    private long page;
    private List<T> data;

    public static <M> PageResult<M> parsePage(IPage<M> page) {
        PageResult<M> PageResult = new PageResult<>();
        PageResult.setCurrent(page.getCurrent());
        PageResult.setSize(page.getSize());
        PageResult.setTotal(page.getTotal());
        PageResult.setPage(page.getPages());
        PageResult.setData(page.getRecords());
        PageResult.setCode(200);
      //  PageResult.setSuccess(true);
        return PageResult;
    }

    public static <T> PageResult<T> emptyPage() {
        PageResult<T> PageResult = new PageResult<>();
        PageResult.setCurrent(0);
        PageResult.setSize(0);
        PageResult.setTotal(0);
        PageResult.setPage(0);
       // PageResult.setData();
        PageResult.setCode(204);
     //   PageResult.setSuccess(false);
        return PageResult;
    }
}